<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  
  <title>Transformer家族之Transformer-InDIGO | Rogerspy&#39;s Home</title>
  
  <meta name="keywords" content="Machine Learning, Deep Learning, NLP">
  
  

  
  <link rel="alternate" href="/atom.xml" title="Rogerspy's Home">
  

  <meta name="HandheldFriendly" content="True">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <!-- meta -->
  
  
  <meta name="theme-color" content="#FFFFFF">
  <meta name="msapplication-TileColor" content="#1BC3FB">
  <meta name="msapplication-config" content="https://cdn.jsdelivr.net/gh/xaoxuu/assets@master/favicon/favicons/browserconfig.xml">
  

  <!-- link -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css">
  
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-waves@0.7.6/dist/waves.min.css">
  
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.10.1/css/all.min.css">
  
  
  <link rel="shortcut icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/xaoxuu/assets@master/favicon/favicon.ico">
  <link rel="icon" type="image/x-icon" sizes="32x32" href="https://cdn.jsdelivr.net/gh/xaoxuu/assets@master/favicon/favicons/favicon-32x32.png">
  <link rel="apple-touch-icon" type="image/png" sizes="180x180" href="https://cdn.jsdelivr.net/gh/xaoxuu/assets@master/favicon/favicons/apple-touch-icon.png">
  <link rel="mask-icon" color="#1BC3FB" href="https://cdn.jsdelivr.net/gh/xaoxuu/assets@master/favicon/favicons/safari-pinned-tab.svg">
  <link rel="manifest" href="https://cdn.jsdelivr.net/gh/xaoxuu/assets@master/favicon/favicons/site.webmanifest">
  

  

  
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-material-x@19.5/css/style.css">
  

  <script>
    function setLoadingBarProgress(num) {
      document.getElementById('loading-bar').style.width=num+"%";
    }
  </script>
  

  
  
  <!-- 时间线 -->
  <link rel="stylesheet" href="/css/timeline.css">
  <!-- 血小板-->
  <link rel="stylesheet" href="/live2d/css/live2d.css">
  <style>
	.article p .mjx-math {
	    font-family: Menlo,Monaco,courier,monospace,"Lucida Console",'Source Code Pro',"Microsoft YaHei",Helvetica,Arial,sans-serif,Ubuntu;
        background: none;
        padding: 2px;
        border-radius: 4px;
	}
  </style>
</head>

<body>
  
  
  <div class="cover-wrapper">
    <cover class='cover post half'>
      
        
  <h1 class='title'>Rogerspy's Home</h1>


  <div class="m_search">
    <form name="searchform" class="form u-search-form">
      <input type="text" class="input u-search-input" placeholder="" />
      <i class="icon fas fa-search fa-fw"></i>
    </form>
  </div>

<div class='menu navgation'>
  <ul class='h-list'>
    
      
        <li>
          <a class="nav home" href="/"
            
            
            id="home">
            <i class='fas fa-edit fa-fw'></i>&nbsp;博文
          </a>
        </li>
      
        <li>
          <a class="nav home" href="/video/"
            
            
            id="video">
            <i class='fas fa-film fa-fw'></i>&nbsp;视频
          </a>
        </li>
      
        <li>
          <a class="nav home" href="/material/"
            
              rel="nofollow"
            
            
            id="material">
            <i class='fas fa-briefcase fa-fw'></i>&nbsp;资料
          </a>
        </li>
      
        <li>
          <a class="nav home" href="/about/"
            
              rel="nofollow"
            
            
            id="about">
            <i class='fas fa-info-circle fa-fw'></i>&nbsp;关于
          </a>
        </li>
      
    
  </ul>
</div>

      
    </cover>
    <header class="l_header pure">
  <div id="loading-bar-wrapper">
    <div id="loading-bar" class="pure"></div>
  </div>

	<div class='wrapper'>
		<div class="nav-main container container--flex">
      <a class="logo flat-box" href='/' >
        
          Rogerspy's Home
        
      </a>
			<div class='menu navgation'>
				<ul class='h-list'>
          
  					
  						<li>
								<a class="nav flat-box" href="/blog/"
                  
                  
                  id="blog">
									<i class='fas fa-edit fa-fw'></i>&nbsp;博客
								</a>
							</li>
      			
  						<li>
								<a class="nav flat-box" href="/video/"
                  
                  
                  id="video">
									<i class='fas fa-film fa-fw'></i>&nbsp;视频小站
								</a>
							</li>
      			
  						<li>
								<a class="nav flat-box" href="/material/"
                  
                  
                  id="material">
									<i class='fas fa-briefcase fa-fw'></i>&nbsp;学习资料
								</a>
							</li>
      			
  						<li>
								<a class="nav flat-box" href="/diary/"
                  
                  
                  id="diary">
									<i class='fas fa-book fa-fw'></i>&nbsp;随心记
								</a>
							</li>
      			
  						<li>
								<a class="nav flat-box" href="/categories/"
                  
                    rel="nofollow"
                  
                  
                  id="categories">
									<i class='fas fa-folder-open fa-fw'></i>&nbsp;分类
								</a>
							</li>
      			
  						<li>
								<a class="nav flat-box" href="/tags/"
                  
                    rel="nofollow"
                  
                  
                  id="tags">
									<i class='fas fa-hashtag fa-fw'></i>&nbsp;标签
								</a>
							</li>
      			
  						<li>
								<a class="nav flat-box" href="/blog/archives/"
                  
                    rel="nofollow"
                  
                  
                  id="blogarchives">
									<i class='fas fa-archive fa-fw'></i>&nbsp;归档
								</a>
							</li>
      			
      		
				</ul>
			</div>

			
				<div class="m_search">
					<form name="searchform" class="form u-search-form">
						<input type="text" class="input u-search-input" placeholder="搜索" />
						<i class="icon fas fa-search fa-fw"></i>
					</form>
				</div>
			
			<ul class='switcher h-list'>
				
					<li class='s-search'><a class="fas fa-search fa-fw" href='javascript:void(0)'></a></li>
				
				<li class='s-menu'><a class="fas fa-bars fa-fw" href='javascript:void(0)'></a></li>
			</ul>
		</div>

		<div class='nav-sub container container--flex'>
			<a class="logo flat-box"></a>
			<ul class='switcher h-list'>
				<li class='s-comment'><a class="flat-btn fas fa-comments fa-fw" href='javascript:void(0)'></a></li>
        
          <li class='s-toc'><a class="flat-btn fas fa-list fa-fw" href='javascript:void(0)'></a></li>
        
			</ul>
		</div>
	</div>
</header>
	<aside class="menu-phone">
    <header>
		<nav class="menu navgation">
      <ul>
        
          
            <li>
							<a class="nav flat-box" href="/"
                
                
                id="home">
								<i class='fas fa-clock fa-fw'></i>&nbsp;近期文章
							</a>
            </li>
          
            <li>
							<a class="nav flat-box" href="/blog/archives/"
                
                  rel="nofollow"
                
                
                id="blogarchives">
								<i class='fas fa-archive fa-fw'></i>&nbsp;文章归档
							</a>
            </li>
          
            <li>
							<a class="nav flat-box" href="/blog/"
                
                
                id="blog">
								<i class='fas fa-edit fa-fw'></i>&nbsp;我的博客
							</a>
            </li>
          
            <li>
							<a class="nav flat-box" href="/video/"
                
                  rel="nofollow"
                
                
                id="video">
								<i class='fas fa-film fa-fw'></i>&nbsp;我的视频
							</a>
            </li>
          
            <li>
							<a class="nav flat-box" href="/material/"
                
                  rel="nofollow"
                
                
                id="material">
								<i class='fas fa-briefcase fa-fw'></i>&nbsp;学习资料
							</a>
            </li>
          
            <li>
							<a class="nav flat-box" href="/about/"
                
                  rel="nofollow"
                
                
                id="about">
								<i class='fas fa-info-circle fa-fw'></i>&nbsp;关于小站
							</a>
            </li>
          
       
      </ul>
		</nav>
    </header>
	</aside>
<script>setLoadingBarProgress(40);</script>

  </div>


  <div class="l_body">
    <div class='body-wrapper'>
      <div class='l_main'>
  

  
    <article id="post" class="post white-box article-type-post" itemscope itemprop="blogPost">
      


  <section class='meta'>
    
    
    <div class="meta" id="header-meta">
      
        
  
    <h1 class="title">
      <a href="/2020/04/24/transformer家族-indigo/">
        Transformer家族之Transformer-InDIGO
      </a>
    </h1>
  


      
      <div class='new-meta-box'>
        
          
        
          
            
  <div class='new-meta-item author'>
    <a href="https://rogerspy.gitee.io" rel="nofollow">
      
        <i class="fas fa-user" aria-hidden="true"></i>
      
      <p>Rogerspy</p>
    </a>
  </div>


          
        
          
            <div class="new-meta-item date">
  <a class='notlink'>
    <i class="fas fa-calendar-alt" aria-hidden="true"></i>
    <p>2020-04-24</p>
  </a>
</div>

          
        
          
            
  
  <div class='new-meta-item category'>
    <a href='/categories/nlp/' rel="nofollow">
      <i class="fas fa-folder-open" aria-hidden="true"></i>
      <p>NLP</p>
    </a>
  </div>


          
        
          
            
  
    <div class="new-meta-item browse busuanzi">
      <a class='notlink'>
        <i class="fas fa-eye" aria-hidden="true"></i>
        <p>
          <span id="busuanzi_value_page_pv">
            <i class="fas fa-spinner fa-spin fa-fw" aria-hidden="true"></i>
          </span>
        </p>
      </a>
    </div>
  


          
        
          
            

          
        
          
            
  
    <div style="margin-right: 10px;">
      <span class="post-time">
        <span class="post-meta-item-icon">
          <i class="fa fa-keyboard"></i>
          <span class="post-meta-item-text">  字数统计: </span>
          <span class="post-count">3.7k字</span>
        </span>
      </span>
      &nbsp; | &nbsp;
      <span class="post-time">
        <span class="post-meta-item-icon">
          <i class="fa fa-hourglass-half"></i>
          <span class="post-meta-item-text">  阅读时长≈</span>
          <span class="post-count">15分</span>
        </span>
      </span>
    </div>
  

          
        
      </div>
      
        <hr>
      
    </div>
  </section>


      <section class="article typo">
        <div class="article-entry" itemprop="articleBody">
          <p><img src="https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/5396ee05ly1g5pqn3ch6zj20u092znph.jpg" alt></p>
<p>之前我们介绍的 <em>insertion-based</em> 生成模型实际上都是人为预先定义了生成顺序或者策略，那么我们能不能让模型自己决定要以怎样的顺序生成呢？这就是本文将要讨论的一种解决方案：<em><a href="https://arxiv.org/pdf/1902.01370.pdf" target="_blank" rel="noopener">Insertion-based Decoding with automatically Inferred Generation Order</a></em>，将序列的生成顺序当成一种隐变量，让模型在预测下一个词的时候自动推理这个词应该所处的位置。</p>
<a id="more"></a>
<h1 id="1-Abstract-Framework"><a href="#1-Abstract-Framework" class="headerlink" title="1. Abstract Framework"></a>1. Abstract Framework</h1><ul>
<li>$y=(y_1, …, y_T)$ —— 表示待生成的序列；</li>
<li>$x=(x_1, …, x_{T’})$ —— 表示输入序列；</li>
<li>$\pi=(z_2, …,z_T,z_{T+1}) \in \mathcal{P}_T$ —— 表示 $y$ 生成的顺序，其中 $\mathcal{P}_T$ 表示 $(1, …, T)$ 的排列组合；</li>
<li>$y_{\pi} = \{(y_2,z_2),…,(y_{T+1}, z_{T+1})\}$ ——每一步生成的词及其位置。</li>
</ul>
<p>与一般的标记不同，这里我们分别令 $(y_0, z_0) = (&lt; s &gt;, 0), (y_1, z_1) = (&lt; /s &gt;, T+1)$，表示序列的开始和结尾。</p>
<p>将生成顺序看作隐变量 $\pi$ ，那么对于一个输出句子 $y$ ，取所有顺序的概率之和，作为输出 $y$ 的概率：</p>
<script type="math/tex; mode=display">
p_\theta(y|x) = \sum_{\pi \in \mathcal{P}_T} p_\theta (y_\pi|x)</script><p>其中每个生成顺序的概率为：</p>
<script type="math/tex; mode=display">
p_\theta(y_\pi|x) = p_\theta(y_{T+2}|y_{0:T+1}, z_{0:T+1}, x_{1:T'}) \cdot \prod_{t=1}^Tp_\theta(y_{t+1}, z_{t+1}|y_{0:t}, z_{0:t}, x_{1:T'})</script><p>其中 $y_{T+2}=&lt; eod &gt;$ 表示结束解码的标志，用 $p(y_{T+2}|\cdot)$ 表示其概率分布。</p>
<p>另外 $z$ 表示生成的单词在句子中的绝对位置。但是这就会有一个问题：我们连最后生成的句序列长度都还不知道怎么能确定当前生成的词在最终序列的绝对位置呢？为了解决这个问题作者提出一个相对位置的概念。</p>
<h1 id="2-InDIGO"><a href="#2-InDIGO" class="headerlink" title="2. InDIGO"></a>2. InDIGO</h1><h2 id="2-1-Relative-Positions"><a href="#2-1-Relative-Positions" class="headerlink" title="2.1 Relative Positions"></a>2.1 Relative Positions</h2><p>为了解决绝对位置编码问题，作者提出相对位置 $r_{0:t}^t$ 来替代 $z_{0:t}^t$。$r_i^t \in \{-1, 0, 1\}^{t+1}$，且：</p>
<script type="math/tex; mode=display">
r_{i,j}^t=\begin{cases}
-1 & z_j^t > z_i^t & (\mathrm{left})\\\\
0 & z_j^t 0 z_i^t & (\mathrm{middle}) \\\\
1 & z_j^t < z_i^t & (\mathrm{right})
\end{cases}</script><p>假设在 $t$ 时刻，对于第 $i$ 个词 $w_i$，用一个向量表示它的相对位置，每个维度取值只有 $(-1, 0, 1)$ 三种。$r_{i,j}^t$ 表示如果 $w_i$ 出现在 $w_j$ 的左边，则取 $-1$，如果出现在右边，则取 $1$，如果是同一个词，则取$0$。使用 $R^t=(r_0^t, r_1^t, …r_t^t)$ 表示序列中所有词的相对位置，每一列表示一个单词的位置向量，这个矩阵关于主对角线对称的元素其实是相反数。举个例子：</p>
<p><img src="https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/20200426152417.png" alt></p>
<blockquote>
<ul>
<li>$t=1$ 时，初始化序列：$y=(&lt; s &gt;, &lt; /s &gt;)$，初始化矩阵 $R=\left[\begin{array}{cc}0 &amp; 1 \\ -1 &amp; 0 \end{array} \right]$ 。矩阵 $R$ 第一列 $r_0^1=[0,-1]$ 表示 $&lt; s &gt;$ 的相对位置向量：$&lt; s &gt;$ 相对于 $&lt; s &gt;$ 自身，因为是同一个词，所以取值为 $0$；$&lt; s &gt;$ 相对于 $&lt; /s &gt;$ 是在左边，所以取值为 $-1$。同理 $R$ 的第二列表示 $&lt; /s &gt;$ 相对位置向量。</li>
<li>$t=2$ 时，$y = (&lt; s &gt;, &lt; /s &gt;, dream)$，$R = \left[\begin{array}{ccc} 0&amp; 1&amp; 1\\ -1&amp; 0&amp; -1\\ -1&amp; 1&amp; 0 \end{array}\right]$，$dream$ 相对于 $&lt; s &gt;$ 在其右边，所以相对位置向量第一维是 $1$；相对于 $&lt; /s &gt;$ 在其左边，所以相对位置向量第二维是 $-1$，相对于 $dream$ 自身，所以第三维是 $0$。</li>
<li>$t=3$ 时，$y = (&lt; s &gt;, &lt; /s &gt;, dream, I)$，$R = \left[\begin{array}{cccc}0&amp; 1&amp; 1&amp; 1\\ -1&amp; 0&amp; -1&amp; -1\\ -1&amp; 1&amp; 0&amp; -1\\  -1&amp; 1&amp; 1&amp; 0\end{array}\right]$，$I$ 相对于 $&lt; s &gt;$ 在其右边，第一维是 $1$；相对于 $&lt; /s &gt;$ 在其左边，第二维是 $-1$；相对于 $dream$ 在其左边，第三维是 $-1$，最后相对于自身，取值$0$。</li>
<li>以此类推…</li>
</ul>
</blockquote>
<p>$R$ 这样一个相对位置矩阵的最大优势是，在下一刻计算相对位置的时候这个矩阵不需要重新计算，因为下一个词无论插在哪里都不会影响之前的词的相对顺序，所以在更新 $R$  的时候只需要给 $R$ 新增一行一列即可：</p>
<p><img src="https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/20200426163728.png" alt></p>
<p>得到相对位置之后，我们就可以使用下式将相对位置映射成绝对位置了：</p>
<script type="math/tex; mode=display">
z_i^t = \sum_{j=0}^t\max (0, r_{i, j}^t)</script><p>还以上面的例子加以说明：</p>
<blockquote>
<ul>
<li>$t=2$ 时，$y = (&lt; s &gt;, &lt; /s &gt;, dream)$，$r_{&lt; s &gt;, j}^2 = (0, -1, -1)$，$z_{&lt; s &gt;}^2=\sum_j \max(0, r_{&lt; s &gt;, j}^2)=0$，所以 $&lt; s &gt;$ 的绝对位置是 $0$；$r_{&lt; /s &gt;, j}^2 = (1, 0, 1)$，$z_{&lt; /s &gt;}^2=\sum_j \max(0, r_{&lt; /s &gt;, j}^2)=2$，所以 $&lt; /s &gt;$ 的绝对位置是 $2$；$r_{dream, j}^2 = (1, -1, 0)$，$z_{dream}^2=\sum_j \max(0, r_{dream, j}^2)=1$，所以$dream$ 的绝对位置是 $1$。</li>
<li>$t=3$ 时，$y = (&lt; s &gt;, &lt; /s &gt;, dream, I)$，$r_{&lt; s &gt;, j}^2 = (0, -1, -1, -1)$，$z_{&lt; s &gt;}^2=\sum_j \max(0, r_{&lt; s &gt;, j}^2)=0$，所以 $&lt; s &gt;$ 的绝对位置是 $0$；$r_{&lt; /s &gt;, j}^2 = (1, 0, 1, 1)$，$z_{&lt; /s &gt;}^2=\sum_j \max(0, r_{&lt; /s &gt;, j}^2)=3$，所以 $&lt; /s &gt;$ 的绝对位置是 $3$；$r_{dream, j}^2 = (1, -1, 0, 1)$，$z_{dream}^2=\sum_j \max(0, r_{dream, j}^2)=2$，所以 $dream$ 的绝对位置是 $2$；$r_{I, j}^2 = (1, -1, -1, 0)$，$z_{I}^2=\sum_j \max(0, r_{I, j}^2)=1$，所以 $I$ 的绝对位置是 $1$。</li>
<li>以此类推…</li>
</ul>
</blockquote>
<p>其实上面的式子的物理意义也很好理解：看相对位置向量中有多少个 $1$ 就表明该词在多少个词的右边，这样我们就可以知道该词所处的绝对位置了。</p>
<h2 id="2-2-Insertion-based-Decoding"><a href="#2-2-Insertion-based-Decoding" class="headerlink" title="2.2 Insertion-based Decoding"></a>2.2 Insertion-based Decoding</h2><p>给定一个长度为 $t$ 的序列 $y_{0:t}$  以及相对位置 $r_{0:t}$ ， 下一个词 $y_{t+1}$ 的相对位置的取值有 $3^{t+2}$ 种可能性，显然并不是任意一种可能性都能满足序列正确排序的要求的，我们需要找到最可能的 $r_{t+1}$。</p>
<p> <img src="https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/20200426175835.png" alt></p>
<p>上图给出了一种算法框架：先从现有的序列中选取一个词 $y_k$， 其中 $0 \le k \le t$，然后向其左边或者右边插入 $y_{t+1}$，$r_{t+1}$ 由下式决定：</p>
<script type="math/tex; mode=display">
r_{t+1, j} = \begin{cases}
s & j=k \\\\
r_{k, j} & j \ne k 
\end{cases}</script><p>其中如果 $y_{t+1}$ 插入 $y_k$ 的左边，则 $s=-1$；如果 $y_{t+1}$ 插入 $y_k$ 的右边，则 $s=1$，然后更新 $R$。</p>
<p>继续用上面的例子说明：</p>
<blockquote>
<ul>
<li>$t=1$ 时，假设我们选的 $y_k=&lt; s &gt;$，$y_{2}=dream$，其中 $k=0$，$j=k=0$ ，$dream$ 在 $&lt; s &gt;$ 的右边，所以 $r_{2, 0} = 1$；$j=1$，$r_{0, 1} = -1$，所以  $r_{2, 1}=r_{0, 1}=-1$，由于 $j=2$ 是$dream$ 本身，所以 $r_{2, 2}=0$。这样我们就得到了 $dream$ 的相对位置向量： $(1, -1, 0)$;</li>
<li>$t=2$ 时，假设我们选的 $y_k = dream$，$y_3 = I$，其中 $k = 2$，$j=0$， $r_{2, 0}=1$，所以 $r_{3, 0} = 1$；$j=1$，$r_{3, 1}=r_{2, 1}=-1$；$j=2$，$j=k=2$，$I$ 在 $dream$ 的左边，所以 $r_{3,2}=-1$；$j=3$ 是 $I$ 自身，所以 $r_{3,3}=0$。这样我们就得到了 $I$ 的相对位置向量：$(1, -1, -1, 0)$；</li>
<li>依次类推…</li>
</ul>
</blockquote>
<p>上面这个公式的物理意义也是很好理解的：首先我们要确定 $y_{t+1}$ 要插在哪个位置，这个位置有两种表示方式：第一，<em>slot</em>，也就是用两个词形成一个空隙， $y_{t+1}$ 就插在这个空隙里面；第二，<em>s</em>，也就是一个词的左右，我们找到一个词 $y_k$，$y_k$有左右两侧，左边就是 $-1$， 右边就是 $1$。之前我们介绍的方法都是使用 <em>slot</em>，显然，这里使用的是 <em>s</em>。序列中其他的词对 $y_{t+1}$ 相对位置和对 $y_{k}$ 是一样的（因为不考虑 $y_k$本身的话， 实际上 $y_{t+1}$ 就是插在了 $y_k$ 的位置上），所以直接使用 $r_{k, j}$ 即可。比如 $t$ 时刻的序列是 $(A, B, C, D)$，推理 $t+1$ 时刻的时候 $y_k=C$，$y_{t+1}=E$，对于 $(A, B, D)$ 来说，我们是把 $E$ 插在了 $C$ 的位置上 $(A, B, D)$ 相对 $C$ 和 $D$ 的相对位置是一样的。</p>
<p>从上面的描述来看，我们现在还有两个问题没有解决：</p>
<ol>
<li>$y_k$ 怎么选择？</li>
<li>$s$ 左右怎么确定？</li>
</ol>
<p>这两个问题我们就需要通过模型结构来解决了。</p>
<h1 id="3-Transformer-InDIGO"><a href="#3-Transformer-InDIGO" class="headerlink" title="3. Transformer-InDIGO"></a>3. Transformer-InDIGO</h1><p><img src="https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/20200427100319.png" alt></p>
<p>整个模型框架包含三部分：</p>
<ul>
<li><em>(a)</em> —— 词和位置预测模块；</li>
<li><em>(b)</em> —— 相对位置矩阵更新；</li>
<li><em>(c)</em> —— 重排序后的序列输出。</li>
</ul>
<p>在传统的 <em>Transformer</em> 结构中有一个零件叫做 <em>positional encoding</em>，这是一个绝对位置的编码，但现在解码器的绝对位置是未知的，所以这部分是需要进行修改的。</p>
<p>令 $U=(u_0, …, u_t)$ 表示 $y_{0:t}$ 序列经过 <em>Embedding</em> 之后的隐层，$R^t$ 是其对应的相对位置矩阵。修改后的注意开计算方法如下：</p>
<script type="math/tex; mode=display">
e_{i, j} = \frac{(u_i^TQ)\cdot(u_j^TK+A_{[r_{i, j}+1]})^T}{\sqrt{d_{model}}}</script><p>其中$Q, K \in \mathbb{R}^{d_{model}\times d_{model}}$，$A \in \mathbb{R}^{3 \times d_{model}}$ 是参数矩阵，$A_{[r_{i, j}+1]}$ 表示第 $r_{i, j}+1$ 列。</p>
<h2 id="3-1-Word-amp-Position-Prediction"><a href="#3-1-Word-amp-Position-Prediction" class="headerlink" title="3.1 Word &amp; Position Prediction"></a>3.1 Word &amp; Position Prediction</h2><p>  经过自注意力的计算之后我们得到一个矩阵 $H$，下一个词及其位置概率为：</p>
<script type="math/tex; mode=display">
p(y_{t+1}, r_{t+1} | H) = p(y_{t+1}|H) \cdot p(r_{t+1}|y_{t+1}， H)</script><p>也就是先预测下一个单词是什么，再预测它的相对位置。当然也可以倒过来，只是实验效果不如这个。</p>
<ul>
<li><p><strong>预测 $y_{t+1}$</strong></p>
<script type="math/tex; mode=display">
p_{\mathrm{word}} (y|H) = \mathrm{softmax}((h_t^TF)\cdot W^T)</script><p>其中 $W \in \mathbb{R}^{d_V \times d_{model}}$ 表示词向量矩阵，$d_V$ 表示词表大小，$F \in \mathbb{R}^{d_{model} \times d_{model}}$ 是用来将 $h_t$ 线性变换的权重矩阵。</p>
</li>
<li><p><strong>预测 $k$</strong></p>
<p>这里我们就要回答上一节我们遗留的两个问题 $y_k$ 和 $s$ 我们怎么确定？</p>
<script type="math/tex; mode=display">
p_{\mathrm{pointer}}(k|y_{t+1}, H) = \mathrm{softmax}\left( (h_t^TE+W_{[y_{t+1}]})\cdot \left[\begin{array}{ccc} H^TC \\ H^TD\end{array}\right]^T\right)</script><p>其中 $C,D,E \in \mathbb{R}^{d_{model}\times d_{model}}$，$W_{[y_{t+1}]}$ 是 $y_{t+1}$ 的词向量。$C, D$ 是分别用来获取左、右的矩阵。注意我们最后得到的 $k_{t+1} \in [0, 2t+1]$，因为每个词都有左右两个位置。另外，为了避免 $y_{t+1}$ 出现在 $&lt; s &gt;$ 的左边和 $&lt; /s &gt;$ 的右边，作者手动设置 $p_{\mathrm{pointer}}(0|\cdot)=p_{\mathrm{pointer}}(2+t|\cdot) = 0$。</p>
<blockquote>
<p>一个词在 $y_k$ 的右边实际上等价于在 $y_{k+1}$ 的左边。那其实这两个预测结果都是对的。虽然最后的 $r$ 向量都是一样的。</p>
</blockquote>
</li>
</ul>
<p>相对位置的更新和输出序列的重排序我们前面已经介绍了，这里就不再赘言。</p>
<h2 id="3-2-Learning"><a href="#3-2-Learning" class="headerlink" title="3.2 Learning"></a>3.2 Learning</h2><p>因为一个句子的可能排列顺序太多了，不可能一一枚举，所以这里最大化 <em>ELBO（evidence lower-bound ）</em> 来代替最开始的概率之和。</p>
<p>对于输入 $x$ 和输出 $y$，首先定义一个生成顺序 $\pi$ 的近似后验 $q(\pi|x, y)$。然后 <em>ELBO</em> 可以表示为：</p>
<script type="math/tex; mode=display">
\begin{equation}\nonumber
\begin{split}
\mathcal{L}_{\mathrm{ELBO}} &= \mathbb{E}_{\pi \sim q} \log p_\theta(y_\pi|x) + \mathcal{H}(q)\\\\
&= \mathbb{E}_{r_{2:T+1}\sim q}\left(\sum_{t=1}^{T+1}\underbrace{\log p_\theta(y_{t+1}|y_{0:t}, r_{0:t}, x_{1:T'})}_{生成下一个字符} + \sum_{t=1}^{T}\underbrace{\log p_\theta(r_{t+1}|y_{0:t+1}, r_{0:t}, x_{1:T'})}_{生成下一个字符的相对位置} \right) + \mathcal{H}(q)  
\end{split}
\end{equation}</script><p>其中 $\pi = r_{2:T+1}$， 表示从 $q(\pi|x, y)$ 中采样的相对位置， $\mathcal{H}(q)$ 表示熵项，如果 $q$ 是固定的，那么这一项可以忽略。</p>
<p>为了计算位置损失，作者这里定义：</p>
<script type="math/tex; mode=display">
p_\theta(r_{t+1}) = p_{\mathrm{pointer}}(k^l|\cdot)+p_{\mathrm{pointer}}(k^r|\cdot)</script><p>$k^l$ 和 $k^r$ 就是我们前面讲的  $y_k$ 的右边等价于在 $y_{k+1}$ 的左边。</p>
<p>然后就可以根据近似后验来进行采样，优化这个函数了，那么这个近似后验怎么定义呢？作者这里考两种方法：</p>
<ul>
<li><p>常见的确定顺序，如下表：</p>
<p><img src="https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/20200427114103.png" alt></p>
<p>这种情况下，模型其实就变成了和普通的序列生成模型差不多了，只用最大化一个生成顺序的概率就行了，区别就是多了相对位置编码。</p>
</li>
<li><p><em>Searched Adaptive Order (SAO)</em>，其实就是 <em>beam search</em>。传统的序列生成模型其实也有 <em>beam search</em>，不过那是在每个时刻解码概率最大那些子序列。 而这里的 <em>beam search</em> 空间更大，搜索的是整个排列的空间。 也就是在每个时刻，遍历所有的下一个单词和它的相对位置，找出最大的 $B$ 个子序列。 最后的目标函数变为了：</p>
<script type="math/tex; mode=display">
\mathcal{L}_{\mathrm{SAO}} = \frac{1}{B}\sum_{\pi \in \mathcal{B}} \log p_\theta(y_\pi|x)</script><p>这里作者假设：</p>
<script type="math/tex; mode=display">
q(\pi|x, y) = \begin{cases}
1/B, & \pi \in \mathcal{B}\\\\
0, & \mathrm{otherwise}
\end{cases}</script></li>
</ul>
<p>上面的 <em>beam search</em> 可以帮助我们找到贪心下最优的生成顺序，但是，同时也减少了生成全局最优的可能性，为此，我们可以在 <em>beam search</em> 的同时加入 <em>dropout</em>。</p>
<p>在实际的实验中，用上面的方法导致模型生成很多标点和功能符号，这是因为位置预测模块的学习比字符预测模块的学习快得多。为此，我们可以用一种固定顺序如 <em>L2R</em> 去预训练整个模型，然后再用<em>SAO</em> 去微调。</p>
<blockquote>
<p>现在我们可以由模型生成任意顺序了，但是，这种方法有一个问题：不能并行。因为该方法还是需要一个一个去生成字符和位置。</p>
</blockquote>
<h1 id="4-Experiments"><a href="#4-Experiments" class="headerlink" title="4. Experiments"></a>4. Experiments</h1><p>实验主要做了机器翻译、词序还原、代码生成和图像标签生成，这里就简单看一下机器翻译结果，其他的详见论文。</p>
<p><img src="https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/20200427115841.png" alt></p>
<p>这里，中间的若干行都是不同的自回归生成策略。可以看到，在三个数据集和各种指标下，<em>SAO</em> 都比自回归好。下面给出一个实际的例子：</p>
<p><img src="https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/20200427120201.png" alt></p>
<h1 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h1><ol>
<li><p><em><a href="https://arxiv.org/pdf/1902.01370.pdf" target="_blank" rel="noopener">Insertion-based Decoding with automatically Inferred Generation Order</a>, Jiatao Gu , Qi Liu , Kyunghyun Cho. 2019. arXiv: 1902.01370</em></p>
</li>
<li><p><a href="https://zhuanlan.zhihu.com/p/73417154" target="_blank" rel="noopener">香侬读 | 按什么套路生成？基于插入和删除的序列生成方法</a>, 香侬科技, 知乎</p>
</li>
<li><a href="https://zhuanlan.zhihu.com/p/101185011?utm_source=wechat_session" target="_blank" rel="noopener">论文赏析[TACL19]生成模型还在用自左向右的顺序？这篇论文教你如何自动推测最佳生成顺序</a>, <em>godweiyang</em>, 知乎</li>
<li><em><a href="https://github.com/kweonwooj/papers/issues/122" target="_blank" rel="noopener">Insertion-based Decoding with Automatically Inferred Generation Order #122</a>, kweonwooj, Github Pages</em></li>
</ol>

        </div>
        
          


  <section class='meta' id="footer-meta">
    <hr>
    <div class='new-meta-box'>
      
        
          <div class="new-meta-item date" itemprop="dateUpdated" datetime="2021-08-23T01:05:27+08:00">
  <a class='notlink'>
    <i class="fas fa-clock" aria-hidden="true"></i>
    <p>最后更新于 2021年8月23日</p>
  </a>
</div>

        
      
        
          
  
  <div class="new-meta-item meta-tags"><a class="tag" href="/tags/transformer/" rel="nofollow"><i class="fas fa-hashtag" aria-hidden="true"></i>&nbsp;<p>Transformer</p></a></div> <div class="new-meta-item meta-tags"><a class="tag" href="/tags/nmt/" rel="nofollow"><i class="fas fa-hashtag" aria-hidden="true"></i>&nbsp;<p>NMT</p></a></div> <div class="new-meta-item meta-tags"><a class="tag" href="/tags/insertion/" rel="nofollow"><i class="fas fa-hashtag" aria-hidden="true"></i>&nbsp;<p>insertion</p></a></div>


        
      
        
          
  <div class="new-meta-item share -mob-share-list">
  <div class="-mob-share-list share-body">
    
      
        <a class="-mob-share-qq" title="QQ好友" rel="external nofollow noopener noreferrer"
          
          href="http://connect.qq.com/widget/shareqq/index.html?url=https://rogerspy.gitee.io/2020/04/24/transformer家族-indigo/&title=Transformer家族之Transformer-InDIGO | Rogerspy's Home&summary=
之前我们介绍的 insertion-based 生成模型实际上都是人为预先定义了生成顺序或者策略，那么我们能不能让模型自己决定要以怎样的顺序生成呢？这就是本文将要讨论的一种解决方案：Insertion-based Decoding with automatically Inferred Generation Order，将序列的生成顺序当成一种隐变量，让模型在预测下一个词的时候自动推理这个词应该所处的位置。"
          
          >
          
            <img src="https://cdn.jsdelivr.net/gh/xaoxuu/assets@19.1.9/logo/128/qq.png">
          
        </a>
      
    
      
        <a class="-mob-share-qzone" title="QQ空间" rel="external nofollow noopener noreferrer"
          
          href="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=https://rogerspy.gitee.io/2020/04/24/transformer家族-indigo/&title=Transformer家族之Transformer-InDIGO | Rogerspy's Home&summary=
之前我们介绍的 insertion-based 生成模型实际上都是人为预先定义了生成顺序或者策略，那么我们能不能让模型自己决定要以怎样的顺序生成呢？这就是本文将要讨论的一种解决方案：Insertion-based Decoding with automatically Inferred Generation Order，将序列的生成顺序当成一种隐变量，让模型在预测下一个词的时候自动推理这个词应该所处的位置。"
          
          >
          
            <img src="https://cdn.jsdelivr.net/gh/xaoxuu/assets@19.1.9/logo/128/qzone.png">
          
        </a>
      
    
      
        <a class='qrcode' rel="external nofollow noopener noreferrer" href=''>
        
          <img src="https://cdn.jsdelivr.net/gh/xaoxuu/assets@19.1.9/logo/128/wechat.png">
        
        </a>
      
    
      
        <a class="-mob-share-weibo" title="微博" rel="external nofollow noopener noreferrer"
          
          href="http://service.weibo.com/share/share.php?url=https://rogerspy.gitee.io/2020/04/24/transformer家族-indigo/&title=Transformer家族之Transformer-InDIGO | Rogerspy's Home&summary=
之前我们介绍的 insertion-based 生成模型实际上都是人为预先定义了生成顺序或者策略，那么我们能不能让模型自己决定要以怎样的顺序生成呢？这就是本文将要讨论的一种解决方案：Insertion-based Decoding with automatically Inferred Generation Order，将序列的生成顺序当成一种隐变量，让模型在预测下一个词的时候自动推理这个词应该所处的位置。"
          
          >
          
            <img src="https://cdn.jsdelivr.net/gh/xaoxuu/assets@19.1.9/logo/128/weibo.png">
          
        </a>
      
    
  </div>
</div>



        
      
    </div>
  </section>


        
        
            <div class="prev-next">
                
                    <section class="prev">
                        <span class="art-item-left">
                            <h6><i class="fas fa-chevron-left" aria-hidden="true"></i>&nbsp;上一页</h6>
                            <h4>
                                <a href="/2020/04/27/transformer家族-levt/" rel="prev" title="Transformer家族之Levenshtein Transformer">
                                  
                                      Transformer家族之Levenshtein Transformer
                                  
                                </a>
                            </h4>
                            
                                
                                <h6 class="tags">
                                    <a class="tag" href="/tags/transformer/"><i class="fas fa-hashtag fa-fw" aria-hidden="true"></i>Transformer</a> <a class="tag" href="/tags/nmt/"><i class="fas fa-hashtag fa-fw" aria-hidden="true"></i>NMT</a> <a class="tag" href="/tags/insertion-deletion/"><i class="fas fa-hashtag fa-fw" aria-hidden="true"></i>insertion-deletion</a>
                                </h6>
                            
                        </span>
                    </section>
                
                
                    <section class="next">
                        <span class="art-item-right" aria-hidden="true">
                            <h6>下一页&nbsp;<i class="fas fa-chevron-right" aria-hidden="true"></i></h6>
                            <h4>
                                <a href="/2020/04/21/transformer家族-non-monotonic/" rel="prev" title="Transformer家族之Non-Monotonic Transformer">
                                    
                                        Transformer家族之Non-Monotonic Transformer
                                    
                                </a>
                            </h4>
                            
                                
                                <h6 class="tags">
                                    <a class="tag" href="/tags/transformer/"><i class="fas fa-hashtag fa-fw" aria-hidden="true"></i>Transformer</a> <a class="tag" href="/tags/nmt/"><i class="fas fa-hashtag fa-fw" aria-hidden="true"></i>NMT</a> <a class="tag" href="/tags/lstm/"><i class="fas fa-hashtag fa-fw" aria-hidden="true"></i>LSTM</a>
                                </h6>
                            
                        </span>
                    </section>
                
            </div>
        
      </section>
    </article>
  

  
    <!-- 显示推荐文章和评论 -->



  <article class="post white-box comments">
    <section class="article typo">
      <h4><i class="fas fa-comments fa-fw" aria-hidden="true"></i>&nbsp;评论</h4>
      
      
      
        <section id="comments">
          <div id="gitalk-container"></div>
        </section>
      
      
    </section>
  </article>


  




<!-- 根据页面mathjax变量决定是否加载MathJax数学公式js -->

  <!-- MathJax配置，可通过单美元符号书写行内公式等 -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    "HTML-CSS": {
      preferredFont: "TeX",
      availableFonts: ["STIX","TeX"],
      linebreaks: { automatic:true },
      EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50)
    },
    tex2jax: {
      inlineMath: [ ["$", "$"], ["\\(","\\)"] ],
      processEscapes: true,
      ignoreClass: "tex2jax_ignore|dno",
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
      equationNumbers: { autoNumber: "AMS" },
      noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } },
      Macros: { href: "{}" }
    },
    messageStyle: "none"
  });
</script>
<!-- 给MathJax元素添加has-jax class -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
      all[i].SourceElement().parentNode.className += (all[i].SourceElement().parentNode.className ? ' ' : '') + 'has-jax';
    }
  });
</script>
<!-- 通过连接CDN加载MathJax的js代码 -->
<script type="text/javascript" async
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">
</script>




  <script>
    window.subData = {
      title: 'Transformer家族之Transformer-InDIGO',
      tools: true
    }
  </script>


</div>
<aside class='l_side'>
  
    
    
      
        
          
          
            <section class='widget shake author'>
  <div class='content pure'>
    
      <div class='avatar'>
        <img class='avatar' src='https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/65-1Z31313530JC.jpeg'/>
      </div>
    
    
    
      <div class="social-wrapper">
        
          
            <a href="/atom.xml"
              class="social fas fa-rss flat-btn"
              target="_blank"
              rel="external nofollow noopener noreferrer">
            </a>
          
        
          
            <a href="mailto:rogerspy@163.com"
              class="social fas fa-envelope flat-btn"
              target="_blank"
              rel="external nofollow noopener noreferrer">
            </a>
          
        
          
            <a href="https://github.com/rogerspy"
              class="social fab fa-github flat-btn"
              target="_blank"
              rel="external nofollow noopener noreferrer">
            </a>
          
        
          
            <a href="https://music.163.com/#/user/home?id=1960721923"
              class="social fas fa-headphones-alt flat-btn"
              target="_blank"
              rel="external nofollow noopener noreferrer">
            </a>
          
        
      </div>
    
  </div>
</section>

          
        
      
        
          
          
            
  <section class='widget toc-wrapper'>
    
<header class='pure'>
  <div><i class="fas fa-list fa-fw" aria-hidden="true"></i>&nbsp;&nbsp;本文目录</div>
  
    <div class='wrapper'><a class="s-toc rightBtn" rel="external nofollow noopener noreferrer" href="javascript:void(0)"><i class="fas fa-thumbtack fa-fw"></i></a></div>
  
</header>

    <div class='content pure'>
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-Abstract-Framework"><span class="toc-text">1. Abstract Framework</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-InDIGO"><span class="toc-text">2. InDIGO</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#2-1-Relative-Positions"><span class="toc-text">2.1 Relative Positions</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-2-Insertion-based-Decoding"><span class="toc-text">2.2 Insertion-based Decoding</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-Transformer-InDIGO"><span class="toc-text">3. Transformer-InDIGO</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-1-Word-amp-Position-Prediction"><span class="toc-text">3.1 Word &amp; Position Prediction</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-2-Learning"><span class="toc-text">3.2 Learning</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#4-Experiments"><span class="toc-text">4. Experiments</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Reference"><span class="toc-text">Reference</span></a></li></ol>
    </div>
  </section>


          
        
      
        
          
          
            <section class='widget grid'>
  
<header class='pure'>
  <div><i class="fas fa-map-signs fa-fw" aria-hidden="true"></i>&nbsp;&nbsp;站内导航</div>
  
</header>

  <div class='content pure'>
    <ul class="grid navgation">
      
        <li><a class="flat-box" " href="/"
          
          
          id="home">
          
            <i class="fas fa-clock fa-fw" aria-hidden="true"></i>
          
          近期文章
        </a></li>
      
        <li><a class="flat-box" " href="/blog/"
          
          
          id="blog">
          
            <i class="fas fa-edit fa-fw" aria-hidden="true"></i>
          
          我的博客
        </a></li>
      
        <li><a class="flat-box" " href="/paper_note/"
          
          
          id="paper_note">
          
            <i class="fas fa-book fa-fw" aria-hidden="true"></i>
          
          论文笔记
        </a></li>
      
        <li><a class="flat-box" " href="/algorithm/"
          
          
          id="algorithm">
          
            <i class="fas fa-cube fa-fw" aria-hidden="true"></i>
          
          算法基础
        </a></li>
      
        <li><a class="flat-box" " href="/leetcode/"
          
          
          id="leetcode">
          
            <i class="fas fa-code fa-fw" aria-hidden="true"></i>
          
          Leetcode
        </a></li>
      
        <li><a class="flat-box" " href="/video/"
          
          
          id="video">
          
            <i class="fas fa-film fa-fw" aria-hidden="true"></i>
          
          视频小站
        </a></li>
      
        <li><a class="flat-box" " href="/material/"
          
          
          id="material">
          
            <i class="fas fa-briefcase fa-fw" aria-hidden="true"></i>
          
          学习资料
        </a></li>
      
        <li><a class="flat-box" " href="/dataset/"
          
          
          id="dataset">
          
            <i class="fas fa-database fa-fw" aria-hidden="true"></i>
          
          数据集
        </a></li>
      
        <li><a class="flat-box" " href="/articles/"
          
          
          id="articles">
          
            <i class="fas fa-sticky-note fa-fw" aria-hidden="true"></i>
          
          杂文天地
        </a></li>
      
        <li><a class="flat-box" " href="/blog/archives/"
          
            rel="nofollow"
          
          
          id="blogarchives">
          
            <i class="fas fa-archive fa-fw" aria-hidden="true"></i>
          
          文章归档
        </a></li>
      
        <li><a class="flat-box" " href="/personal_center/"
          
          
          id="personal_center">
          
            <i class="fas fa-university fa-fw" aria-hidden="true"></i>
          
          个人中心
        </a></li>
      
        <li><a class="flat-box" " href="/about/"
          
            rel="nofollow"
          
          
          id="about">
          
            <i class="fas fa-info-circle fa-fw" aria-hidden="true"></i>
          
          关于小站
        </a></li>
      
    </ul>
  </div>
</section>

          
        
      
        
          
          
            <section class='widget list'>
  
<header class='pure'>
  <div><i class="fas fa-terminal fa-fw" aria-hidden="true"></i>&nbsp;&nbsp;机器学习框架</div>
  
</header>

  <div class='content pure'>
    <ul class="entry">
      
        <li><a class="flat-box" title="https://rogerspy.gitee.io/pytorch-zh/" href="https://rogerspy.gitee.io/pytorch-zh/"
          
          
          >
          <div class='name'>
            
              <i class="fas fa-star fa-fw" aria-hidden="true"></i>
            
            &nbsp;&nbsp;PyTorch 中文文档
          </div>
          
        </a></li>
      
        <li><a class="flat-box" title="https://keras-zh.readthedocs.io/" href="https://keras-zh.readthedocs.io/"
          
          
          >
          <div class='name'>
            
              <i class="fas fa-star fa-fw" aria-hidden="true"></i>
            
            &nbsp;&nbsp;Keras 中文文档
          </div>
          
        </a></li>
      
        <li><a class="flat-box" title="https://tensorflow.google.cn/" href="https://tensorflow.google.cn/"
          
          
          >
          <div class='name'>
            
              <i class="fas fa-star fa-fw" aria-hidden="true"></i>
            
            &nbsp;&nbsp;Tensorflow 中文文档
          </div>
          
        </a></li>
      
        <li><a class="flat-box" title="http://scikitlearn.com.cn/" href="http://scikitlearn.com.cn/"
          
          
          >
          <div class='name'>
            
              <i class="fas fa-star fa-fw" aria-hidden="true"></i>
            
            &nbsp;&nbsp;Scikit Learn 中文文档
          </div>
          
        </a></li>
      
    </ul>
  </div>
</section>

          
        
      
        
          
          
            <section class='widget list'>
  
<header class='pure'>
  <div><i class="fas fa-wrench fa-fw" aria-hidden="true"></i>&nbsp;&nbsp;百宝箱</div>
  
</header>

  <div class='content pure'>
    <ul class="entry">
      
        <li><a class="flat-box" title="https://rogerspy.github.io/excalidraw-claymate/" href="https://rogerspy.github.io/excalidraw-claymate/"
          
          
            target="_blank"
          
          >
          <div class='name'>
            
              <i class="fas fa-magic fa-fw" aria-hidden="true"></i>
            
            &nbsp;&nbsp;Excalidraw-Claymate
          </div>
          
        </a></li>
      
        <li><a class="flat-box" title="https://rogerspy.github.io/jupyterlite/" href="https://rogerspy.github.io/jupyterlite/"
          
          
            target="_blank"
          
          >
          <div class='name'>
            
              <i class="fas fa-terminal fa-fw" aria-hidden="true"></i>
            
            &nbsp;&nbsp;JupyterLite
          </div>
          
        </a></li>
      
    </ul>
  </div>
</section>

          
        
      
        
          
          
            <section class='widget list'>
  
<header class='pure'>
  <div><i class="fas fa-eye fa-fw" aria-hidden="true"></i>&nbsp;&nbsp;睁眼看世界</div>
  
</header>

  <div class='content pure'>
    <ul class="entry">
      
        <li><a class="flat-box" title="https://deeplearn.org/" href="https://deeplearn.org/"
          
          
          >
          <div class='name'>
            
              <i class="fas fa-link fa-fw" aria-hidden="true"></i>
            
            &nbsp;&nbsp;Deep Learning Monitor
          </div>
          
        </a></li>
      
        <li><a class="flat-box" title="https://paperswithcode.com/sota" href="https://paperswithcode.com/sota"
          
          
          >
          <div class='name'>
            
              <i class="fas fa-link fa-fw" aria-hidden="true"></i>
            
            &nbsp;&nbsp;Browse State-of-the-Art
          </div>
          
        </a></li>
      
        <li><a class="flat-box" title="https://huggingface.co/transformers/" href="https://huggingface.co/transformers/"
          
          
          >
          <div class='name'>
            
              <i class="fas fa-link fa-fw" aria-hidden="true"></i>
            
            &nbsp;&nbsp;Transformers
          </div>
          
        </a></li>
      
        <li><a class="flat-box" title="https://huggingface.co/models" href="https://huggingface.co/models"
          
          
          >
          <div class='name'>
            
              <i class="fas fa-link fa-fw" aria-hidden="true"></i>
            
            &nbsp;&nbsp;Transformers-models
          </div>
          
        </a></li>
      
    </ul>
  </div>
</section>

          
        
      
        
          
          
            
  <section class='widget category'>
    
<header class='pure'>
  <div><i class="fas fa-folder-open fa-fw" aria-hidden="true"></i>&nbsp;&nbsp;文章分类</div>
  
    <a class="rightBtn"
    
      rel="nofollow"
    
    
    href="/categories/"
    title="categories/">
    <i class="fas fa-expand-arrows-alt fa-fw"></i></a>
  
</header>

    <div class='content pure'>
      <ul class="entry">
        
          <li><a class="flat-box" title="/categories/nl2sql/" href="/categories/nl2sql/"><div class='name'>NL2SQL</div><div class='badge'>(1)</div></a></li>
        
          <li><a class="flat-box" title="/categories/nlp/" href="/categories/nlp/"><div class='name'>NLP</div><div class='badge'>(23)</div></a></li>
        
          <li><a class="flat-box" title="/categories/博客转载/" href="/categories/博客转载/"><div class='name'>博客转载</div><div class='badge'>(5)</div></a></li>
        
          <li><a class="flat-box" title="/categories/数据结构与算法/" href="/categories/数据结构与算法/"><div class='name'>数据结构与算法</div><div class='badge'>(11)</div></a></li>
        
          <li><a class="flat-box" title="/categories/知识图谱/" href="/categories/知识图谱/"><div class='name'>知识图谱</div><div class='badge'>(3)</div></a></li>
        
          <li><a class="flat-box" title="/categories/论文解读/" href="/categories/论文解读/"><div class='name'>论文解读</div><div class='badge'>(2)</div></a></li>
        
          <li><a class="flat-box" title="/categories/语言模型/" href="/categories/语言模型/"><div class='name'>语言模型</div><div class='badge'>(10)</div></a></li>
        
      </ul>
    </div>
  </section>


          
        
      
        
          
          
            
  <section class='widget tagcloud'>
    
<header class='pure'>
  <div><i class="fas fa-fire fa-fw" aria-hidden="true"></i>&nbsp;&nbsp;热门标签</div>
  
    <a class="rightBtn"
    
      rel="nofollow"
    
    
    href="/tags/"
    title="tags/">
    <i class="fas fa-expand-arrows-alt fa-fw"></i></a>
  
</header>

    <div class='content pure'>
      <a href="/tags/attention/" style="font-size: 16.86px; color: #868686">Attention</a> <a href="/tags/cnnlm/" style="font-size: 14px; color: #999">CNNLM</a> <a href="/tags/data-structure/" style="font-size: 14px; color: #999">Data Structure</a> <a href="/tags/deep/" style="font-size: 14px; color: #999">Deep</a> <a href="/tags/ffnnlm/" style="font-size: 14px; color: #999">FFNNLM</a> <a href="/tags/gaussian/" style="font-size: 14px; color: #999">Gaussian</a> <a href="/tags/initialization/" style="font-size: 14px; color: #999">Initialization</a> <a href="/tags/kg/" style="font-size: 16.86px; color: #868686">KG</a> <a href="/tags/lstm/" style="font-size: 14px; color: #999">LSTM</a> <a href="/tags/lstmlm/" style="font-size: 14px; color: #999">LSTMLM</a> <a href="/tags/language-model/" style="font-size: 16.86px; color: #868686">Language Model</a> <a href="/tags/log-linear-language-model/" style="font-size: 14px; color: #999">Log-Linear Language Model</a> <a href="/tags/nlp/" style="font-size: 19.71px; color: #727272">NLP</a> <a href="/tags/nmt/" style="font-size: 22.57px; color: #5f5f5f">NMT</a> <a href="/tags/norm/" style="font-size: 14px; color: #999">Norm</a> <a href="/tags/probabilistic-language-model/" style="font-size: 14px; color: #999">Probabilistic Language Model</a> <a href="/tags/rnnlm/" style="font-size: 14px; color: #999">RNNLM</a> <a href="/tags/roc-auc/" style="font-size: 14px; color: #999">ROC-AUC</a> <a href="/tags/transformer/" style="font-size: 24px; color: #555">Transformer</a> <a href="/tags/context2vec/" style="font-size: 14px; color: #999">context2vec</a> <a href="/tags/divide-conquer/" style="font-size: 14px; color: #999">divide-conquer</a> <a href="/tags/insertion/" style="font-size: 16.86px; color: #868686">insertion</a> <a href="/tags/insertion-deletion/" style="font-size: 15.43px; color: #8f8f8f">insertion-deletion</a> <a href="/tags/knowledge-modelling/" style="font-size: 15.43px; color: #8f8f8f">knowledge-modelling</a> <a href="/tags/nl2infographic/" style="font-size: 14px; color: #999">nl2infographic</a> <a href="/tags/nl2sql/" style="font-size: 14px; color: #999">nl2sql</a> <a href="/tags/ontology/" style="font-size: 14px; color: #999">ontology</a> <a href="/tags/parallel-recurrent/" style="font-size: 14px; color: #999">parallel-recurrent</a> <a href="/tags/pytorch/" style="font-size: 14px; color: #999">pytorch</a> <a href="/tags/queue/" style="font-size: 18.29px; color: #7c7c7c">queue</a> <a href="/tags/sparse/" style="font-size: 14px; color: #999">sparse</a> <a href="/tags/stack/" style="font-size: 14px; color: #999">stack</a> <a href="/tags/tensorflow/" style="font-size: 14px; color: #999">tensorflow</a> <a href="/tags/text2viz/" style="font-size: 14px; color: #999">text2viz</a> <a href="/tags/weighted-head/" style="font-size: 14px; color: #999">weighted-head</a> <a href="/tags/半监督语言模型/" style="font-size: 14px; color: #999">半监督语言模型</a> <a href="/tags/双数组前缀树/" style="font-size: 14px; color: #999">双数组前缀树</a> <a href="/tags/推荐系统/" style="font-size: 14px; color: #999">推荐系统</a> <a href="/tags/数据结构/" style="font-size: 21.14px; color: #686868">数据结构</a> <a href="/tags/数组/" style="font-size: 14px; color: #999">数组</a> <a href="/tags/时间复杂度/" style="font-size: 14px; color: #999">时间复杂度</a> <a href="/tags/算法/" style="font-size: 14px; color: #999">算法</a> <a href="/tags/评估方法/" style="font-size: 14px; color: #999">评估方法</a> <a href="/tags/词向量/" style="font-size: 14px; color: #999">词向量</a> <a href="/tags/隐式正则化/" style="font-size: 14px; color: #999">隐式正则化</a>
    </div>
  </section>


          
        
      
        
          
          
            


  <section class='widget music'>
    
<header class='pure'>
  <div><i class="fas fa-compact-disc fa-fw" aria-hidden="true"></i>&nbsp;&nbsp;最近在听</div>
  
    <a class="rightBtn"
    
      rel="external nofollow noopener noreferrer"
    
    
      target="_blank"
    
    href="https://music.163.com/#/user/home?id=1960721923"
    title="https://music.163.com/#/user/home?id=1960721923">
    <i class="far fa-heart fa-fw"></i></a>
  
</header>

    <div class='content pure'>
      
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.7.0/dist/APlayer.min.css">
  <div class="aplayer"
    data-theme="#1BCDFC"
    
    
    data-mode="circulation"
    data-server="netease"
    data-type="playlist"
    data-id="2957571193"
    data-volume="0.7">
  </div>
  <script src="https://cdn.jsdelivr.net/npm/aplayer@1.7.0/dist/APlayer.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/meting@1.1.0/dist/Meting.min.js"></script>


    </div>
  </section>


          
        
      
    

  
</aside>

<footer id="footer" class="clearfix">
  <div id="sitetime"></div>
  
  
    <div class="social-wrapper">
      
        
          <a href="/atom.xml"
            class="social fas fa-rss flat-btn"
            target="_blank"
            rel="external nofollow noopener noreferrer">
          </a>
        
      
        
          <a href="mailto:rogerspy@163.com"
            class="social fas fa-envelope flat-btn"
            target="_blank"
            rel="external nofollow noopener noreferrer">
          </a>
        
      
        
          <a href="https://github.com/rogerspy"
            class="social fab fa-github flat-btn"
            target="_blank"
            rel="external nofollow noopener noreferrer">
          </a>
        
      
        
          <a href="https://music.163.com/#/user/home?id=1960721923"
            class="social fas fa-headphones-alt flat-btn"
            target="_blank"
            rel="external nofollow noopener noreferrer">
          </a>
        
      
    </div>
  
  <br>
  <div><p>博客内容遵循 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议</a></p>
</div>
  <div>
    本站使用
    <a href="https://xaoxuu.com/wiki/material-x/" target="_blank" class="codename">Material X</a>
    作为主题
    
      ，
      总访问量为
      <span id="busuanzi_value_site_pv"><i class="fas fa-spinner fa-spin fa-fw" aria-hidden="true"></i></span>
      次
    
    。
  </div>
	</footer>

<script>setLoadingBarProgress(80);</script>
<!-- 点击特效，输入特效 运行时间 -->
<script type="text/javascript" src="/cool/cooltext.js"></script>
<script type="text/javascript" src="/cool/clicklove.js"></script>
<script type="text/javascript" src="/cool/sitetime.js"></script>



      <script>setLoadingBarProgress(60);</script>
    </div>
    <a class="s-top fas fa-arrow-up fa-fw" href='javascript:void(0)'></a>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>

  <script>
    var GOOGLE_CUSTOM_SEARCH_API_KEY = "";
    var GOOGLE_CUSTOM_SEARCH_ENGINE_ID = "";
    var ALGOLIA_API_KEY = "";
    var ALGOLIA_APP_ID = "";
    var ALGOLIA_INDEX_NAME = "";
    var AZURE_SERVICE_NAME = "";
    var AZURE_INDEX_NAME = "";
    var AZURE_QUERY_KEY = "";
    var BAIDU_API_ID = "";
    var SEARCH_SERVICE = "hexo" || "hexo";
    var ROOT = "/"||"/";
    if(!ROOT.endsWith('/'))ROOT += '/';
  </script>

<script src="//instant.page/1.2.2" type="module" integrity="sha384-2xV8M5griQmzyiY3CDqh1dn4z3llDVqZDqzjzcY+jCBCk/a5fXJmuZ/40JJAPeoU"></script>


  <script async src="https://cdn.jsdelivr.net/npm/scrollreveal@4.0.5/dist/scrollreveal.min.js"></script>
  <script type="text/javascript">
    $(function() {
      const $reveal = $('.reveal');
      if ($reveal.length === 0) return;
      const sr = ScrollReveal({ distance: 0 });
      sr.reveal('.reveal');
    });
  </script>


  <script src="https://cdn.jsdelivr.net/npm/node-waves@0.7.6/dist/waves.min.js"></script>
  <script type="text/javascript">
    $(function() {
      Waves.attach('.flat-btn', ['waves-button']);
      Waves.attach('.float-btn', ['waves-button', 'waves-float']);
      Waves.attach('.float-btn-light', ['waves-button', 'waves-float', 'waves-light']);
      Waves.attach('.flat-box', ['waves-block']);
      Waves.attach('.float-box', ['waves-block', 'waves-float']);
      Waves.attach('.waves-image');
      Waves.init();
    });
  </script>


  <script async src="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-busuanzi@2.3/js/busuanzi.pure.mini.js"></script>




  
  
  
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-backstretch/2.0.4/jquery.backstretch.min.js"></script>
    <script type="text/javascript">
      $(function(){
        if ('.cover') {
          $('.cover').backstretch(
          ["https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/a0c9e6f9efad8b731cb7376504bd10d79d2053.jpg"],
          {
            duration: "6000",
            fade: "2500"
          });
        } else {
          $.backstretch(
          ["https://cdn.jsdelivr.net/gh/rogerspy/blog-imgs/a0c9e6f9efad8b731cb7376504bd10d79d2053.jpg"],
          {
            duration: "6000",
            fade: "2500"
          });
        }
      });
    </script>
  







  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
  <script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
  <script type="text/javascript">
    var gitalk = new Gitalk({
      clientID: "35a5e4dc744cc7d162af",
      clientSecret: "7b5a409e17ce0c1971f284eac9f8902eb4b8feba",
      repo: "rogerspy.github.io",
      owner: "Rogerspy",
      admin: "Rogerspy",
      
        id: "/wiki/material-x/",
      
      distractionFreeMode: false  // Facebook-like distraction free mode
    });
    gitalk.render('gitalk-container');
  </script>





  <script src="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-material-x@19.5/js/app.js"></script>


  <script src="https://cdn.jsdelivr.net/gh/xaoxuu/cdn-material-x@19.5/js/search.js"></script>




<!-- 复制 -->
<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  let COPY_SUCCESS = "复制成功";
  let COPY_FAILURE = "复制失败";
  /*页面载入完成后，创建复制按钮*/
  !function (e, t, a) {
    /* code */
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '  <i class="fa fa-copy"></i><span>复制</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });

      clipboard.on('success', function(e) {
        //您可以加入成功提示
        console.info('Action:', e.action);
        console.info('Text:', e.text);
        console.info('Trigger:', e.trigger);
        success_prompt(COPY_SUCCESS);
        e.clearSelection();
      });
      clipboard.on('error', function(e) {
        //您可以加入失败提示
        console.error('Action:', e.action);
        console.error('Trigger:', e.trigger);
        fail_prompt(COPY_FAILURE);
      });
    }
    initCopyCode();

  }(window, document);

  /**
   * 弹出式提示框，默认1.5秒自动消失
   * @param message 提示信息
   * @param style 提示样式，有alert-success、alert-danger、alert-warning、alert-info
   * @param time 消失时间
   */
  var prompt = function (message, style, time)
  {
      style = (style === undefined) ? 'alert-success' : style;
      time = (time === undefined) ? 1500 : time*1000;
      $('<div>')
          .appendTo('body')
          .addClass('alert ' + style)
          .html(message)
          .show()
          .delay(time)
          .fadeOut();
  };

  // 成功提示
  var success_prompt = function(message, time)
  {
      prompt(message, 'alert-success', time);
  };

  // 失败提示
  var fail_prompt = function(message, time)
  {
      prompt(message, 'alert-danger', time);
  };

  // 提醒
  var warning_prompt = function(message, time)
  {
      prompt(message, 'alert-warning', time);
  };

  // 信息提示
  var info_prompt = function(message, time)
  {
      prompt(message, 'alert-info', time);
  };

</script>


<!-- fancybox -->
<script src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>
<script>
  let LAZY_LOAD_IMAGE = "";
  $(".article-entry").find("fancybox").find("img").each(function () {
      var element = document.createElement("a");
      $(element).attr("data-fancybox", "gallery");
      $(element).attr("href", $(this).attr("src"));
      /* 图片采用懒加载处理时,
       * 一般图片标签内会有个属性名来存放图片的真实地址，比如 data-original,
       * 那么此处将原本的属性名src替换为对应属性名data-original,
       * 修改如下
       */
       if (LAZY_LOAD_IMAGE) {
         $(element).attr("href", $(this).attr("data-original"));
       }
      $(this).wrap(element);
  });
</script>





  <script>setLoadingBarProgress(100);</script>
</body>
</html>
